﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections;
using System.IO;
using System.Reflection;
using GrapeCity.PAutoTester.Core;

namespace GrapeCity.PAutoTesterConsole
{
    #region Class CommandLine
    public class CommandLine
    {
        #region Fields

        private string _configFile = string.Empty;
        private string _caseList = string.Empty;
        private string[] _args;
        #endregion

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandLine"/> class.
        /// </summary>
        public CommandLine()
        {
        }

        #endregion

        #region Properties
        /// <summary>
        /// Gets the parsed arguments.
        /// </summary>
        public string[] Args
        {
            get { return this._args; }
        }

        /// <summary>
        /// Gets or sets the config file.
        /// </summary>
        /// <value>
        /// The config file.
        /// </value>
        [Description("Run cases.")]
        public string CaseList
        {
            get { return this._caseList; }
            set { this._caseList = value; }
        }

        /// <summary>
        /// Gets or sets the config file.
        /// </summary>
        /// <value>
        /// The config file.
        /// </value>
        [Description("Full path of autotest tool config file.")]
        public string ConfigFile
        {
            get { return this._configFile; }
            set { this._configFile = value; }
        }

        #endregion

        #region Methods
        public void Parse(string[] args)
        {
            CommandLineParser.ParseArguments(this, args);
            this._args = args;
        }

        /// <summary>
        /// Determines whether [has config file].
        /// </summary>
        /// <returns>
        ///   <c>true</c> if [has config file]; otherwise, <c>false</c>.
        /// </returns>
        public bool HasConfigFile()
        {
            return !string.IsNullOrEmpty(this.ConfigFile);
        }

        public bool HasCaseList()
        {
            return !string.IsNullOrEmpty(this.CaseList);
        }

        /// <summary>
        ///   Write the copy right for autotester
        /// </summary>
        public static void WriteCopyright()
        {
            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            System.Version version = executingAssembly.GetName().Version;

            object[] objectAttrs = executingAssembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
            AssemblyProductAttribute productAttr = (AssemblyProductAttribute)objectAttrs[0];

            objectAttrs = executingAssembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
            AssemblyCopyrightAttribute copyrightAttr = (AssemblyCopyrightAttribute)objectAttrs[0];

            System.Console.WriteLine(string.Format("{0} version {1}", productAttr.Product, version.ToString(3)));
            System.Console.WriteLine(copyrightAttr.Copyright);
            System.Console.WriteLine("");
        }

        #endregion
    }
    #endregion
}
